﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using BesAsm.MasterData.Entities;
using BesAsm.MasterData.Data;

#endregion

namespace BesAsm.MasterData.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="SpecialLinkDatumProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class SpecialLinkDatumProviderBaseCore : EntityProviderBase<BesAsm.MasterData.Entities.SpecialLinkDatum, BesAsm.MasterData.Entities.SpecialLinkDatumKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, BesAsm.MasterData.Entities.SpecialLinkDatumKey key)
		{
			return Delete(transactionManager, key.SpecialLinkDataId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_specialLinkDataId">Primary key, special link data id. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _specialLinkDataId)
		{
			return Delete(null, _specialLinkDataId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_specialLinkDataId">Primary key, special link data id. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _specialLinkDataId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SPECIAL_LINKS_DATA_SPECIAL_LINKS key.
		///		FK_SPECIAL_LINKS_DATA_SPECIAL_LINKS Description: 
		/// </summary>
		/// <param name="_specialLinkId">Foreign key to SPECIAL_LINKS</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SpecialLinkDatum objects.</returns>
		public TList<SpecialLinkDatum> GetBySpecialLinkId(System.Int32? _specialLinkId)
		{
			int count = -1;
			return GetBySpecialLinkId(_specialLinkId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SPECIAL_LINKS_DATA_SPECIAL_LINKS key.
		///		FK_SPECIAL_LINKS_DATA_SPECIAL_LINKS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_specialLinkId">Foreign key to SPECIAL_LINKS</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SpecialLinkDatum objects.</returns>
		/// <remarks></remarks>
		public TList<SpecialLinkDatum> GetBySpecialLinkId(TransactionManager transactionManager, System.Int32? _specialLinkId)
		{
			int count = -1;
			return GetBySpecialLinkId(transactionManager, _specialLinkId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_SPECIAL_LINKS_DATA_SPECIAL_LINKS key.
		///		FK_SPECIAL_LINKS_DATA_SPECIAL_LINKS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_specialLinkId">Foreign key to SPECIAL_LINKS</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SpecialLinkDatum objects.</returns>
		public TList<SpecialLinkDatum> GetBySpecialLinkId(TransactionManager transactionManager, System.Int32? _specialLinkId, int start, int pageLength)
		{
			int count = -1;
			return GetBySpecialLinkId(transactionManager, _specialLinkId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SPECIAL_LINKS_DATA_SPECIAL_LINKS key.
		///		fkSpecialLinksDataSpecialLinks Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_specialLinkId">Foreign key to SPECIAL_LINKS</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SpecialLinkDatum objects.</returns>
		public TList<SpecialLinkDatum> GetBySpecialLinkId(System.Int32? _specialLinkId, int start, int pageLength)
		{
			int count =  -1;
			return GetBySpecialLinkId(null, _specialLinkId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SPECIAL_LINKS_DATA_SPECIAL_LINKS key.
		///		fkSpecialLinksDataSpecialLinks Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_specialLinkId">Foreign key to SPECIAL_LINKS</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SpecialLinkDatum objects.</returns>
		public TList<SpecialLinkDatum> GetBySpecialLinkId(System.Int32? _specialLinkId, int start, int pageLength,out int count)
		{
			return GetBySpecialLinkId(null, _specialLinkId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SPECIAL_LINKS_DATA_SPECIAL_LINKS key.
		///		FK_SPECIAL_LINKS_DATA_SPECIAL_LINKS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_specialLinkId">Foreign key to SPECIAL_LINKS</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SpecialLinkDatum objects.</returns>
		public abstract TList<SpecialLinkDatum> GetBySpecialLinkId(TransactionManager transactionManager, System.Int32? _specialLinkId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SPECIAL_LINKS_DATA_STATUSES key.
		///		FK_SPECIAL_LINKS_DATA_STATUSES Description: 
		/// </summary>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SpecialLinkDatum objects.</returns>
		public TList<SpecialLinkDatum> GetByStatus(System.String _status)
		{
			int count = -1;
			return GetByStatus(_status, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SPECIAL_LINKS_DATA_STATUSES key.
		///		FK_SPECIAL_LINKS_DATA_STATUSES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SpecialLinkDatum objects.</returns>
		/// <remarks></remarks>
		public TList<SpecialLinkDatum> GetByStatus(TransactionManager transactionManager, System.String _status)
		{
			int count = -1;
			return GetByStatus(transactionManager, _status, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_SPECIAL_LINKS_DATA_STATUSES key.
		///		FK_SPECIAL_LINKS_DATA_STATUSES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SpecialLinkDatum objects.</returns>
		public TList<SpecialLinkDatum> GetByStatus(TransactionManager transactionManager, System.String _status, int start, int pageLength)
		{
			int count = -1;
			return GetByStatus(transactionManager, _status, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SPECIAL_LINKS_DATA_STATUSES key.
		///		fkSpecialLinksDataStatuses Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SpecialLinkDatum objects.</returns>
		public TList<SpecialLinkDatum> GetByStatus(System.String _status, int start, int pageLength)
		{
			int count =  -1;
			return GetByStatus(null, _status, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SPECIAL_LINKS_DATA_STATUSES key.
		///		fkSpecialLinksDataStatuses Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SpecialLinkDatum objects.</returns>
		public TList<SpecialLinkDatum> GetByStatus(System.String _status, int start, int pageLength,out int count)
		{
			return GetByStatus(null, _status, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SPECIAL_LINKS_DATA_STATUSES key.
		///		FK_SPECIAL_LINKS_DATA_STATUSES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SpecialLinkDatum objects.</returns>
		public abstract TList<SpecialLinkDatum> GetByStatus(TransactionManager transactionManager, System.String _status, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override BesAsm.MasterData.Entities.SpecialLinkDatum Get(TransactionManager transactionManager, BesAsm.MasterData.Entities.SpecialLinkDatumKey key, int start, int pageLength)
		{
			return GetBySpecialLinkDataId(transactionManager, key.SpecialLinkDataId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_SPECIAL_LINKS_DATA index.
		/// </summary>
		/// <param name="_specialLinkDataId">Primary key, special link data id</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SpecialLinkDatum"/> class.</returns>
		public BesAsm.MasterData.Entities.SpecialLinkDatum GetBySpecialLinkDataId(System.Int32 _specialLinkDataId)
		{
			int count = -1;
			return GetBySpecialLinkDataId(null,_specialLinkDataId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SPECIAL_LINKS_DATA index.
		/// </summary>
		/// <param name="_specialLinkDataId">Primary key, special link data id</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SpecialLinkDatum"/> class.</returns>
		public BesAsm.MasterData.Entities.SpecialLinkDatum GetBySpecialLinkDataId(System.Int32 _specialLinkDataId, int start, int pageLength)
		{
			int count = -1;
			return GetBySpecialLinkDataId(null, _specialLinkDataId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SPECIAL_LINKS_DATA index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_specialLinkDataId">Primary key, special link data id</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SpecialLinkDatum"/> class.</returns>
		public BesAsm.MasterData.Entities.SpecialLinkDatum GetBySpecialLinkDataId(TransactionManager transactionManager, System.Int32 _specialLinkDataId)
		{
			int count = -1;
			return GetBySpecialLinkDataId(transactionManager, _specialLinkDataId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SPECIAL_LINKS_DATA index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_specialLinkDataId">Primary key, special link data id</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SpecialLinkDatum"/> class.</returns>
		public BesAsm.MasterData.Entities.SpecialLinkDatum GetBySpecialLinkDataId(TransactionManager transactionManager, System.Int32 _specialLinkDataId, int start, int pageLength)
		{
			int count = -1;
			return GetBySpecialLinkDataId(transactionManager, _specialLinkDataId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SPECIAL_LINKS_DATA index.
		/// </summary>
		/// <param name="_specialLinkDataId">Primary key, special link data id</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SpecialLinkDatum"/> class.</returns>
		public BesAsm.MasterData.Entities.SpecialLinkDatum GetBySpecialLinkDataId(System.Int32 _specialLinkDataId, int start, int pageLength, out int count)
		{
			return GetBySpecialLinkDataId(null, _specialLinkDataId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SPECIAL_LINKS_DATA index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_specialLinkDataId">Primary key, special link data id</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SpecialLinkDatum"/> class.</returns>
		public abstract BesAsm.MasterData.Entities.SpecialLinkDatum GetBySpecialLinkDataId(TransactionManager transactionManager, System.Int32 _specialLinkDataId, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;SpecialLinkDatum&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;SpecialLinkDatum&gt;"/></returns>
		public static TList<SpecialLinkDatum> Fill(IDataReader reader, TList<SpecialLinkDatum> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				BesAsm.MasterData.Entities.SpecialLinkDatum c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("SpecialLinkDatum")
					.Append("|").Append((System.Int32)reader[((int)SpecialLinkDatumColumn.SpecialLinkDataId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<SpecialLinkDatum>(
					key.ToString(), // EntityTrackingKey
					"SpecialLinkDatum",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new BesAsm.MasterData.Entities.SpecialLinkDatum();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.SpecialLinkDataId = (System.Int32)reader[((int)SpecialLinkDatumColumn.SpecialLinkDataId - 1)];
					c.OriginalSpecialLinkDataId = c.SpecialLinkDataId;
					c.SpecialLinkId = (reader.IsDBNull(((int)SpecialLinkDatumColumn.SpecialLinkId - 1)))?null:(System.Int32?)reader[((int)SpecialLinkDatumColumn.SpecialLinkId - 1)];
					c.TagName = (reader.IsDBNull(((int)SpecialLinkDatumColumn.TagName - 1)))?null:(System.String)reader[((int)SpecialLinkDatumColumn.TagName - 1)];
					c.TextValue = (reader.IsDBNull(((int)SpecialLinkDatumColumn.TextValue - 1)))?null:(System.String)reader[((int)SpecialLinkDatumColumn.TextValue - 1)];
					c.ToLinkIdIndex = (reader.IsDBNull(((int)SpecialLinkDatumColumn.ToLinkIdIndex - 1)))?null:(System.Int32?)reader[((int)SpecialLinkDatumColumn.ToLinkIdIndex - 1)];
					c.EditedBy = (System.String)reader[((int)SpecialLinkDatumColumn.EditedBy - 1)];
					c.EditReason = (System.String)reader[((int)SpecialLinkDatumColumn.EditReason - 1)];
					c.Status = (System.String)reader[((int)SpecialLinkDatumColumn.Status - 1)];
					c.AppendDate = (System.DateTime)reader[((int)SpecialLinkDatumColumn.AppendDate - 1)];
					c.EditDate = (reader.IsDBNull(((int)SpecialLinkDatumColumn.EditDate - 1)))?null:(System.DateTime?)reader[((int)SpecialLinkDatumColumn.EditDate - 1)];
					c.MspeclinkidDeprecated = (reader.IsDBNull(((int)SpecialLinkDatumColumn.MspeclinkidDeprecated - 1)))?null:(System.Int32?)reader[((int)SpecialLinkDatumColumn.MspeclinkidDeprecated - 1)];
					c.SlidDeprecated = (reader.IsDBNull(((int)SpecialLinkDatumColumn.SlidDeprecated - 1)))?null:(System.Int32?)reader[((int)SpecialLinkDatumColumn.SlidDeprecated - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.SpecialLinkDatum"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.SpecialLinkDatum"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, BesAsm.MasterData.Entities.SpecialLinkDatum entity)
		{
			if (!reader.Read()) return;
			
			entity.SpecialLinkDataId = (System.Int32)reader[((int)SpecialLinkDatumColumn.SpecialLinkDataId - 1)];
			entity.OriginalSpecialLinkDataId = (System.Int32)reader["special_link_data_id"];
			entity.SpecialLinkId = (reader.IsDBNull(((int)SpecialLinkDatumColumn.SpecialLinkId - 1)))?null:(System.Int32?)reader[((int)SpecialLinkDatumColumn.SpecialLinkId - 1)];
			entity.TagName = (reader.IsDBNull(((int)SpecialLinkDatumColumn.TagName - 1)))?null:(System.String)reader[((int)SpecialLinkDatumColumn.TagName - 1)];
			entity.TextValue = (reader.IsDBNull(((int)SpecialLinkDatumColumn.TextValue - 1)))?null:(System.String)reader[((int)SpecialLinkDatumColumn.TextValue - 1)];
			entity.ToLinkIdIndex = (reader.IsDBNull(((int)SpecialLinkDatumColumn.ToLinkIdIndex - 1)))?null:(System.Int32?)reader[((int)SpecialLinkDatumColumn.ToLinkIdIndex - 1)];
			entity.EditedBy = (System.String)reader[((int)SpecialLinkDatumColumn.EditedBy - 1)];
			entity.EditReason = (System.String)reader[((int)SpecialLinkDatumColumn.EditReason - 1)];
			entity.Status = (System.String)reader[((int)SpecialLinkDatumColumn.Status - 1)];
			entity.AppendDate = (System.DateTime)reader[((int)SpecialLinkDatumColumn.AppendDate - 1)];
			entity.EditDate = (reader.IsDBNull(((int)SpecialLinkDatumColumn.EditDate - 1)))?null:(System.DateTime?)reader[((int)SpecialLinkDatumColumn.EditDate - 1)];
			entity.MspeclinkidDeprecated = (reader.IsDBNull(((int)SpecialLinkDatumColumn.MspeclinkidDeprecated - 1)))?null:(System.Int32?)reader[((int)SpecialLinkDatumColumn.MspeclinkidDeprecated - 1)];
			entity.SlidDeprecated = (reader.IsDBNull(((int)SpecialLinkDatumColumn.SlidDeprecated - 1)))?null:(System.Int32?)reader[((int)SpecialLinkDatumColumn.SlidDeprecated - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.SpecialLinkDatum"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.SpecialLinkDatum"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, BesAsm.MasterData.Entities.SpecialLinkDatum entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.SpecialLinkDataId = (System.Int32)dataRow["special_link_data_id"];
			entity.OriginalSpecialLinkDataId = (System.Int32)dataRow["special_link_data_id"];
			entity.SpecialLinkId = Convert.IsDBNull(dataRow["special_link_id"]) ? null : (System.Int32?)dataRow["special_link_id"];
			entity.TagName = Convert.IsDBNull(dataRow["tag_name"]) ? null : (System.String)dataRow["tag_name"];
			entity.TextValue = Convert.IsDBNull(dataRow["text_value"]) ? null : (System.String)dataRow["text_value"];
			entity.ToLinkIdIndex = Convert.IsDBNull(dataRow["to_link_id_index"]) ? null : (System.Int32?)dataRow["to_link_id_index"];
			entity.EditedBy = (System.String)dataRow["edited_by"];
			entity.EditReason = (System.String)dataRow["edit_reason"];
			entity.Status = (System.String)dataRow["status"];
			entity.AppendDate = (System.DateTime)dataRow["append_date"];
			entity.EditDate = Convert.IsDBNull(dataRow["edit_date"]) ? null : (System.DateTime?)dataRow["edit_date"];
			entity.MspeclinkidDeprecated = Convert.IsDBNull(dataRow["mspeclinkid_deprecated"]) ? null : (System.Int32?)dataRow["mspeclinkid_deprecated"];
			entity.SlidDeprecated = Convert.IsDBNull(dataRow["slid_deprecated"]) ? null : (System.Int32?)dataRow["slid_deprecated"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.SpecialLinkDatum"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.SpecialLinkDatum Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, BesAsm.MasterData.Entities.SpecialLinkDatum entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region SpecialLinkIdSource	
			if (CanDeepLoad(entity, "SpecialLink|SpecialLinkIdSource", deepLoadType, innerList) 
				&& entity.SpecialLinkIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.SpecialLinkId ?? (int)0);
				SpecialLink tmpEntity = EntityManager.LocateEntity<SpecialLink>(EntityLocator.ConstructKeyFromPkItems(typeof(SpecialLink), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.SpecialLinkIdSource = tmpEntity;
				else
					entity.SpecialLinkIdSource = DataRepository.SpecialLinkProvider.GetBySpecialLinkId(transactionManager, (entity.SpecialLinkId ?? (int)0));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'SpecialLinkIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.SpecialLinkIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.SpecialLinkProvider.DeepLoad(transactionManager, entity.SpecialLinkIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion SpecialLinkIdSource

			#region StatusSource	
			if (CanDeepLoad(entity, "Status|StatusSource", deepLoadType, innerList) 
				&& entity.StatusSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.Status;
				Status tmpEntity = EntityManager.LocateEntity<Status>(EntityLocator.ConstructKeyFromPkItems(typeof(Status), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.StatusSource = tmpEntity;
				else
					entity.StatusSource = DataRepository.StatusProvider.GetByStatusId(transactionManager, entity.Status);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'StatusSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.StatusSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.StatusProvider.DeepLoad(transactionManager, entity.StatusSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion StatusSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the BesAsm.MasterData.Entities.SpecialLinkDatum object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">BesAsm.MasterData.Entities.SpecialLinkDatum instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.SpecialLinkDatum Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, BesAsm.MasterData.Entities.SpecialLinkDatum entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region SpecialLinkIdSource
			if (CanDeepSave(entity, "SpecialLink|SpecialLinkIdSource", deepSaveType, innerList) 
				&& entity.SpecialLinkIdSource != null)
			{
				DataRepository.SpecialLinkProvider.Save(transactionManager, entity.SpecialLinkIdSource);
				entity.SpecialLinkId = entity.SpecialLinkIdSource.SpecialLinkId;
			}
			#endregion 
			
			#region StatusSource
			if (CanDeepSave(entity, "Status|StatusSource", deepSaveType, innerList) 
				&& entity.StatusSource != null)
			{
				DataRepository.StatusProvider.Save(transactionManager, entity.StatusSource);
				entity.Status = entity.StatusSource.StatusId;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region SpecialLinkDatumChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>BesAsm.MasterData.Entities.SpecialLinkDatum</c>
	///</summary>
	public enum SpecialLinkDatumChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>SpecialLink</c> at SpecialLinkIdSource
		///</summary>
		[ChildEntityType(typeof(SpecialLink))]
		SpecialLink,
			
		///<summary>
		/// Composite Property for <c>Status</c> at StatusSource
		///</summary>
		[ChildEntityType(typeof(Status))]
		Status,
		}
	
	#endregion SpecialLinkDatumChildEntityTypes
	
	#region SpecialLinkDatumFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;SpecialLinkDatumColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SpecialLinkDatum"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class SpecialLinkDatumFilterBuilder : SqlFilterBuilder<SpecialLinkDatumColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SpecialLinkDatumFilterBuilder class.
		/// </summary>
		public SpecialLinkDatumFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the SpecialLinkDatumFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public SpecialLinkDatumFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the SpecialLinkDatumFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public SpecialLinkDatumFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion SpecialLinkDatumFilterBuilder
	
	#region SpecialLinkDatumParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;SpecialLinkDatumColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SpecialLinkDatum"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class SpecialLinkDatumParameterBuilder : ParameterizedSqlFilterBuilder<SpecialLinkDatumColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SpecialLinkDatumParameterBuilder class.
		/// </summary>
		public SpecialLinkDatumParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the SpecialLinkDatumParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public SpecialLinkDatumParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the SpecialLinkDatumParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public SpecialLinkDatumParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion SpecialLinkDatumParameterBuilder
	
	#region SpecialLinkDatumSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;SpecialLinkDatumColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SpecialLinkDatum"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class SpecialLinkDatumSortBuilder : SqlSortBuilder<SpecialLinkDatumColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SpecialLinkDatumSqlSortBuilder class.
		/// </summary>
		public SpecialLinkDatumSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion SpecialLinkDatumSortBuilder
	
} // end namespace
